home *** CD-ROM | disk | FTP | other *** search
/ Assassins - Ultimate CD Games Collection 4 / Assassins 4 (1999)(Weird Science).iso / misc / omega / source / village.c < prev   
Encoding:
C/C++ Source or Header  |  1997-05-02  |  6.6 KB  |  300 lines

  1. /* omega copyright (C) by Laurence Raphael Brothers, 1987,1988,1989 */
  2. /* village.c */
  3. /* some functions to make the village levels */
  4.  
  5. #include "glob.h"
  6.  
  7.  
  8. /* loads the village level into Level*/
  9. void load_village(villagenum, populate)
  10. int villagenum;
  11. int populate;
  12. {
  13.   int i,j;
  14.   char site;
  15.   
  16.   FILE *fd;
  17.   
  18.  
  19.   TempLevel = Level;
  20.   if (ok_to_free(TempLevel)) {
  21. #ifndef SAVE_LEVELS
  22.     free_level(TempLevel);
  23. #endif
  24.     TempLevel = NULL;
  25.   }
  26.  
  27.   initrand(Current_Environment, villagenum);
  28.  
  29.   assign_village_function(0,0,TRUE);
  30.  
  31. #ifndef SAVE_LEVELS
  32.   Level = ((plv) checkmalloc(sizeof(levtype)));
  33. #else
  34.   msdos_changelevel(TempLevel,0,-1);
  35.   Level = &TheLevel;
  36. #endif
  37.   clear_level(Level);
  38.   Level->environment = E_VILLAGE;
  39.   strcpy(Str3,Omegalib);
  40.   switch(villagenum) {
  41.   case 1:strcat(Str3,"village1.dat");break;
  42.   case 2:strcat(Str3,"village2.dat");break;
  43.   case 3:strcat(Str3,"village3.dat");break;
  44.   case 4:strcat(Str3,"village4.dat");break;
  45.   case 5:strcat(Str3,"village5.dat");break;
  46.   case 6:strcat(Str3,"village6.dat");break;
  47.   }
  48.   site = cryptkey("village.dat");
  49.   fd = checkfopen(Str3,"rb");
  50.   for(j=0;j<LENGTH;j++) {
  51.     for(i=0;i<WIDTH;i++) {
  52.       lset(i,j,SEEN);
  53.       site = getc(fd)^site;
  54.       Level->site[i][j].p_locf = L_NO_OP;
  55.       switch(site) {
  56.       case 'f':
  57.     Level->site[i][j].locchar = FLOOR;
  58.     if (populate)
  59.       make_food_bin(i,j);
  60.     break;
  61.       case 'g':
  62.     Level->site[i][j].locchar = FLOOR;
  63.     Level->site[i][j].p_locf = L_GRANARY;
  64.     break;
  65.       case 'h':
  66.     Level->site[i][j].locchar = FLOOR;
  67.     if (populate)
  68.       make_horse(i,j);
  69.     break;
  70.       case 'S':
  71.     Level->site[i][j].locchar = FLOOR;
  72.     Level->site[i][j].p_locf = L_STABLES;
  73.     break;
  74.       case 'H':
  75.     Level->site[i][j].locchar = FLOOR;
  76.     if (populate)
  77.       make_merchant(i,j);
  78.     break;
  79.       case 'C':
  80.     Level->site[i][j].locchar = FLOOR;
  81.     Level->site[i][j].p_locf = L_COMMONS;
  82.     break;
  83.       case 's':
  84.     Level->site[i][j].locchar = FLOOR;
  85.     if (populate)
  86.       make_sheep(i,j);
  87.     break;
  88.       case 'x':
  89.     assign_village_function(i,j,FALSE);
  90.     break;
  91.       case 'X':
  92.     Level->site[i][j].locchar = FLOOR;
  93.     Level->site[i][j].p_locf = L_COUNTRYSIDE;
  94.     break;
  95.       case 'G':
  96.     Level->site[i][j].locchar = FLOOR;
  97.     if (populate) {
  98.       make_guard(i,j);
  99.       Level->site[i][j].creature->aux1 = i;
  100.       Level->site[i][j].creature->aux2 = j;
  101.     }
  102.     break;
  103.       case '^':
  104.     Level->site[i][j].locchar = FLOOR;
  105.     Level->site[i][j].p_locf = L_TRAP_SIREN;
  106.     break;
  107.       case '"':
  108.     Level->site[i][j].locchar = HEDGE;
  109.     Level->site[i][j].p_locf = L_HEDGE;
  110.     break;
  111.       case '~':
  112.     Level->site[i][j].locchar = WATER;
  113.     Level->site[i][j].p_locf = L_WATER;
  114.     break;
  115.       case '+':
  116.     Level->site[i][j].locchar = WATER;
  117.     Level->site[i][j].p_locf = L_CHAOS;
  118.     break;
  119.       case '\'':
  120.     Level->site[i][j].locchar = HEDGE;
  121.     Level->site[i][j].p_locf = L_TRIFID;
  122.     break;
  123.       case '!':
  124.     special_village_site(i,j,villagenum);
  125.     break;
  126.       case '#':
  127.     Level->site[i][j].locchar = WALL;
  128.     Level->site[i][j].aux = 100;
  129.     break;
  130.       case '.':
  131.     Level->site[i][j].locchar = FLOOR;
  132.     break;
  133.       case '-':
  134.     Level->site[i][j].locchar = CLOSED_DOOR;
  135.     break;
  136.       case '1':
  137.     Level->site[i][j].locchar = STATUE;
  138.     break;
  139.       }
  140.       if (loc_statusp(i,j,SECRET))
  141.     Level->site[i][j].showchar = WALL;
  142.       else Level->site[i][j].showchar = Level->site[i][j].locchar;
  143.     }
  144.     site = getc(fd)^site;
  145.   }
  146.   fclose(fd);
  147.   initrand(-2, 0);
  148. }
  149.  
  150. void make_guard(i,j)
  151. int i,j;
  152. {
  153.   pml tml = ((pml) (checkmalloc(sizeof(mltype))));
  154.   tml->m = (Level->site[i][j].creature = make_creature(ML0+3));
  155.   tml->m->x = i;
  156.   tml->m->y = j;
  157.   tml->next = Level->mlist;
  158.   Level->mlist = tml;
  159. }
  160.  
  161. void make_sheep(i,j)
  162. int i,j;
  163. {
  164.   pml tml = ((pml) (checkmalloc(sizeof(mltype))));
  165.   tml->m = (Level->site[i][j].creature = make_creature(SHEEP));
  166.   tml->m->x = i;
  167.   tml->m->y = j;
  168.   tml->next = Level->mlist;
  169.   Level->mlist = tml;
  170. }
  171.  
  172. void make_food_bin(i,j)
  173. int i,j;
  174.   pol tol;
  175.   int k;
  176.  
  177.   for(k=0;k<10;k++) {
  178.     tol = ((pol) checkmalloc(sizeof(oltype)));
  179.     tol->thing = ((pob) checkmalloc(sizeof(objtype)));
  180.     make_food(tol->thing,15); /* grain */
  181.     tol->next = Level->site[i][j].things;
  182.     Level->site[i][j].things = tol;
  183.   }
  184. }
  185.  
  186. void make_horse(i,j)
  187. int i,j;
  188. {
  189.   pml tml = ((pml) (checkmalloc(sizeof(mltype))));
  190.   tml->m = (Level->site[i][j].creature = make_creature(HORSE));
  191.   tml->m->x = i;
  192.   tml->m->y = j;
  193.   tml->next = Level->mlist;
  194.   Level->mlist = tml;
  195. }
  196.  
  197.  
  198. void make_merchant(i,j)
  199. int i,j;
  200. {
  201.   pml tml = ((pml) (checkmalloc(sizeof(mltype))));
  202.   tml->m = (Level->site[i][j].creature = make_creature(ML0+6));
  203.   tml->m->x = i;
  204.   tml->m->y = j;
  205.   tml->next = Level->mlist;
  206.   Level->mlist = tml;
  207. }
  208.  
  209.  
  210. void assign_village_function(x,y,setup)
  211. int x,y,setup;
  212. {
  213.   static int next=0;
  214.   static int permutation[24]; /* number of x's in village map */
  215.   int i,j,k;
  216.  
  217.  
  218.   if (setup) {
  219.     next = 0;
  220.     for(i=0;i<24;i++)
  221.       permutation[i] = i;
  222.     for(i=0;i<24;i++) {
  223.       j = permutation[i];
  224.       k = random_range(24);
  225.       permutation[i] = permutation[k];
  226.       permutation[k] = j;
  227.     }
  228.   }
  229.   else {
  230.  
  231.     lset(x,y+1,STOPS);
  232.     lset(x+1,y,STOPS);
  233.     lset(x-1,y,STOPS);
  234.     lset(x,y-1,STOPS);
  235.     
  236.     
  237.     switch(permutation[next++]) {
  238.     case 0:
  239.       Level->site[x][y].locchar = OPEN_DOOR;
  240.       Level->site[x][y].p_locf = L_ARMORER;
  241.       break;
  242.     case 1:
  243.       Level->site[x][y].locchar = OPEN_DOOR;
  244.       Level->site[x][y].p_locf = L_HEALER;
  245.       break;
  246.     case 2: 
  247.       Level->site[x][y].locchar = OPEN_DOOR;
  248.       Level->site[x][y].p_locf = L_TAVERN;
  249.       break;
  250.     case 3:
  251.       Level->site[x][y].locchar = OPEN_DOOR;
  252.       Level->site[x][y].p_locf = L_COMMANDANT;
  253.       break;
  254.     case 4:
  255.       Level->site[x][y].locchar = OPEN_DOOR;
  256.       Level->site[x][y].p_locf = L_CARTOGRAPHER;
  257.       break;
  258.     default:
  259.       Level->site[x][y].locchar = CLOSED_DOOR;
  260.       if (random_range(2)) 
  261.     Level->site[x][y].aux = LOCKED;
  262.       if (random_range(2))
  263.     Level->site[x][y].p_locf = L_HOVEL;
  264.       else Level->site[x][y].p_locf = L_HOUSE;
  265.       break;
  266.     }
  267.   }
  268. }  
  269.   
  270.  
  271. void special_village_site(i,j,villagenum)
  272. int i,j,villagenum;
  273. {
  274.   if (villagenum == 1) {
  275.     Level->site[i][j].locchar = ALTAR;
  276.     Level->site[i][j].p_locf = L_LAWSTONE;
  277.   }
  278.   if (villagenum == 2) {
  279.     Level->site[i][j].locchar = ALTAR;
  280.     Level->site[i][j].p_locf = L_BALANCESTONE;
  281.   }
  282.   else if (villagenum == 3) {
  283.     Level->site[i][j].locchar = ALTAR; 
  284.     Level->site[i][j].p_locf = L_CHAOSTONE; 
  285.   }
  286.   else if (villagenum == 4) {
  287.     Level->site[i][j].locchar = ALTAR; 
  288.     Level->site[i][j].p_locf = L_MINDSTONE; 
  289.   }
  290.   else if (villagenum == 5) {
  291.     Level->site[i][j].locchar = ALTAR; 
  292.     Level->site[i][j].p_locf = L_SACRIFICESTONE; 
  293.   }
  294.   else if (villagenum == 6) {
  295.     Level->site[i][j].locchar = ALTAR; 
  296.     Level->site[i][j].p_locf = L_VOIDSTONE; 
  297.   }
  298. }
  299.